using System.Configuration;

namespace Istace.Framework.Mapping.Core.Configuration
{
    /// <summary>
    /// 
    /// </summary>
    public class MappingAssemblyConfigSection : ConfigurationSection
    {
        /// <summary>
        /// The configuration section name
        /// </summary>
        private const string configurationSectionName = "RegisteredAssemblies";

        /// <summary>
        /// Gets the config section.
        /// </summary>
        /// <value>
        /// The config section.
        /// </value>
        internal static MappingAssemblyConfigSection GetConfigSection()
        {
            return GetConfigSection(configurationSectionName);
        }

        /// <summary>
        /// Gets the config section.
        /// </summary>
        /// <param name="sectionName">Name of the section.</param>
        /// <returns></returns>
        internal static MappingAssemblyConfigSection GetConfigSection(string sectionName)
        {
            if (ConfigurationManager.GetSection(sectionName) == null)
                return new MappingAssemblyConfigSection();
            return (MappingAssemblyConfigSection)ConfigurationManager.GetSection(sectionName);
        }

        /// <summary>
        /// Gets the registred assemblies.
        /// </summary>
        /// <value>
        /// The registred assemblies.
        /// </value>
        [ConfigurationProperty(configurationSectionName)]
        internal MappingAssemblyConfigInstanceCollection RegisteredAssemblies
        {
            get
            {
                if (this[configurationSectionName] == null)
                    return new MappingAssemblyConfigInstanceCollection();
                return (MappingAssemblyConfigInstanceCollection)this[configurationSectionName];
            }
        }

    }
}